<?php
	include_once("../inc/parameters.php");
	include_once("../inc/db.class.php");
	include_once("../inc/JSON.php");

	$field = intval($_POST["field"]);
	switch($field){
		case "1":
			$ord = " order by a.fund_code";
			break;
		case "2":
			$ord = " order by a.name";
			break;
		case "3":
			$ord = " order by a.depot desc";
			break;
		case "4":
			$ord = " order by b.yesterday_value desc";
			break;
		case "5":
			$ord = " order by b.average desc";
			break;
		case "6":
			$ord = " order by b.ourku desc";
			break;
		case "7":
			$ord = " order by b.fund123 desc";
			break;
		case "8":
			$ord = " order by b.eastmoney desc";
			break;
		case "9":
			$ord = " order by b.fundxy desc";
			break;
		default:
			$ord = " order by b.average desc";
			break;
	}

	$sql = "select a.fund_code, a.name, a.depot, a.date,b.yesterday_value, b.ourku, b.fund123, b.eastmoney, b.fundxy,b.average";
	$sql.= " from fund_information a, forecast b where a.fund_code = b.fund_code" . $ord;

	$_MyDB	=	new dbClass();
	$_MyDB->db_connect();
	$_MyDB->query($sql);
	
	$js     = "[";
	$i      = 0;

	while($row = $_MyDB->NextRecord($result))
	{
		if($i != 0)
			$js.= ",";
		
		if($row["depot"] == ""){$row["depot"] = 0;}
		if($row["yesterday_value"] == ""){$row["yesterday_value"] = 0;}
		if($row["ourku"] == ""){$row["ourku"] = 0;}
		if($row["fund123"] == ""){$row["fund123"] = 0;}
		if($row["eastmoney"] == ""){$row["eastmoney"] = 0;}
		if($row["fundxy"] == ""){$row["fundxy"] = 0;}
		if($row["average"] == ""){$row["average"] = 0;}
		
		if($row["ourku"] < 0){$row["ourku_color"] = "green";}elseif($row["ourku"] == '0'){$row["ourku_color"] = "black";}else{$row["ourku_color"] = "red";}
		if($row["fund123"] < 0){$row["fund123_color"] = "green";}elseif($row["fund123"] == '0'){$row["fund123_color"] = "black";}else{$row["fund123_color"] = "red";}
		if($row["eastmoney"] < 0){$row["eastmoney_color"] = "green";}elseif($row["eastmoney"] == '0'){$row["eastmoney_color"] = "black";}else{$row["eastmoney_color"] = "red";}
		if($row["fundxy"] < 0){$row["fundxy_color"] = "green";}elseif($row["fundxy"] == '0'){$row["fundxy_color"] = "black";}else{$row["fundxy_color"] = "red";}
		if($row["average"] < 0){$row["average_color"] = "green";}elseif($row["average"] == '0'){$row["average_color"] = "black";}else{$row["average_color"] = "red";}
		
		$row["avg"] = 0;
		
		//$js.= "['".$row["fund_code"]."', '".urlencode($row["name"])."', '".$row["date"]."', '".$row["depot"]."', '".$row["yesterday_value"]."', '".$row["ourku"]."', '".$row["fund123"]."', '".$row["eastmoney"]."', '".$row["fundxy"]."', '".$row["average"]."', '".$row["ourku_color"]."', '".$row["fund123_color"]."', '".$row["eastmoney_color"]."', '".$row["fundxy_color"]."', '".$row["average_color"]."', ".($i+1)."]";
		$js.= "['".$row["fund_code"]."', '', '".$row["date"]."', '".$row["depot"]."', '".$row["yesterday_value"]."', '".$row["ourku"]."', '".$row["fund123"]."', '".$row["eastmoney"]."', '".$row["fundxy"]."', '".$row["average"]."', '".$row["ourku_color"]."', '".$row["fund123_color"]."', '".$row["eastmoney_color"]."', '".$row["fundxy_color"]."', '".$row["average_color"]."', ".($i+1)."]";
		$i++;
	}
	$js.= "]";

	echo $js;
?>